﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxGridView;
using UdrinkWater_Project;

namespace Project_Udrinkwater.PagesAdmin
{
    public partial class GoodsList : System.Web.UI.Page
    {
        AddProductDataContext db = new AddProductDataContext();
       // DataClassesProductDataContext dbp = new DataClassesProductDataContext();
        string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }

        protected void detailGrid_DataSelect(object sender, EventArgs e)
        {
            Session["Product_ID"] = (sender as ASPxGridView).GetMasterRowKeyValue();
        }

        protected void ASPxGridView1_RowCommand(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewRowCommandEventArgs e)
        {
            if (e.CommandArgs.CommandName == "Cmdedit")
            {
                string GoodID = e.CommandArgs.CommandArgument.ToString();
                Session["Product_ID"] = GoodID;
               // Session["Num"] = 1;

                Response.Redirect("Add_And_Edit_Goods.aspx");
            }
            if (e.CommandArgs.CommandName == "Cmddelete")
            {
                string GoodID = e.CommandArgs.CommandArgument.ToString();
                DeleteGoods(GoodID);
            }
        }

        protected void bt_AddGoods_Click(object sender, EventArgs e)
        {
           Response.Redirect("Add_And_Edit_Goods.aspx");
        }
        public void DeleteGoods(string GoodID)
        {
            var p = from b in db.TB_Products
                    where b.Product_ID == GoodID
                    select b;
            db.TB_Products.DeleteAllOnSubmit(p);
            db.SubmitChanges();
           ASPxGridView1.DataBind();
        }
       
        }
    
}